package com.oocl.mqService;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class MQservice{
	ConnectionFactory factory;
	Destination queue ;
	Connection con;
	Session ss ;
	MessageProducer producer ;
	
	public MQservice() throws JMSException{
		factory = new ActiveMQConnectionFactory("tcp://10.222.29.173:61616");
		queue = new ActiveMQQueue("matthew");
		con = factory.createConnection();
		ss = con.createSession(true, Session.AUTO_ACKNOWLEDGE);
		producer = ss.createProducer(queue);
	}
	
	public void offerMQ(String[] json) throws JMSException{
		Message msg = null;
		for (int i = 0; i < json.length; i++) {
			msg = ss.createTextMessage(json[i]);
			producer.send(msg);
		}
		ss.commit();
	}
	
	public void release() throws JMSException{
		producer.close();
		ss.close();
		con.close();
		
	}
}
